import request from '@/utils/request'

// 创建订单
export function submitOrder(order) {
    return request({
        url: '/order/submit',
        method: 'post',
        data: order
    })
}

// 订单列表
export function orderList(showType, page, limit) {
    return request({
        url: '/order/list',
        method: 'get',
        params: {showType, page, limit}
    })
}

// 查询订单详情
export function orderDetail(orderId) {
    return request({
        url: '/order/detail',
        method: 'get',
        data: {orderId}
    })
}

// 创建支付定单
export function updateUserProfile(orderId) {
    return request({
        url: '/order/prepay',
        method: 'put',
        data: {orderId}
    })
}

/**
 * 支付方法
 *
 * @param payParam 支付参数
 */
export function requestPayment(payParam) {
    return new Promise((resolve, reject) => {
        uni.requestPayment({
            provider: 'wxpay',
            timeStamp: payParam.timeStamp,
            nonceStr: payParam.nonceStr,
            package: payParam.packageValue,
            signType: payParam.signType,
            paySign: payParam.paySign,
            success: function (res) {
                console.log('success:' + JSON.stringify(res));
                resolve(res)
            },
            fail: function (err) {
                console.log('fail:' + JSON.stringify(err));
                reject(err)
            }
        });
    })
}
